﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
namespace UsbGuard.Core
{
    public class USBDeviceInfo
    {
        public USBDeviceInfo(string deviceID, string pnpDeviceID, string description)
        {
            this.DeviceID = deviceID;
            this.PnpDeviceID = pnpDeviceID;
            this.Description = description;
           
        }
        public object GetDriveInfo(string key)
        {
            ManagementObjectCollection collection;
            using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_DiskDrive where InterfaceType='USB'"))
                collection = searcher.Get();

            foreach (var device in collection)
            {
                if ((string)device.GetPropertyValue("DeviceID") == DeviceID) return device.GetPropertyValue(key); 
            }

            collection.Dispose();
            return null;
        }
        public object GetAdditionalInformation(string key)
        {
            ManagementObjectCollection collection;
            using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
                collection = searcher.Get();

            foreach (var device in collection)
            {
                if ((string)device.GetPropertyValue("DeviceID") == DeviceID) return device.GetPropertyValue(key);
            }

            collection.Dispose();
            return null;
        }
        public string DeviceID { get; private set; }
        public string PnpDeviceID { get; private set; }
        public string Description { get; private set; }
    }
}
